// 定义数据结构接口
interface DataItem {
  [key: string]: any;
}

interface DeviceThree {
  id: string | number;
  deviceName?: string | null;
  deviceId: string | number;
  agreementId?: string | null;
  agreementName?: string | null;
  deviceCategory?: string | null;
  deviceMark: string;
  data: DataItem[]; // 包含的第四层数据项
}

interface DeviceTwo {
  deviceId: string | number;
  deviceThreeList: DeviceThree[];
}

interface DeviceOne {
  deviceMark: string;
  deviceTwoList: DeviceTwo[];
}

// 定义树节点基础接口
interface TreeDataNode<T = any> {
  key: string;
  title: string;
  level: number;
  rawData: T;
  children: TreeDataNode[];
  isLeaf?: boolean;
}
import { render } from '/@/utils/common/renderUtils';
export function convertToTreeData(deviceThreeList: DeviceThree[]): TreeDataNode<DeviceThree>[] {
  const treeData: TreeDataNode<DeviceThree>[] = [];
//device_mark
  console.log(deviceThreeList);
   deviceThreeList.forEach((level3: DeviceThree, idx3: number) => {
        // 处理第三层节点（设备详情）
        const level3Node: TreeDataNode<DeviceThree> = {
          key: `L3-${level3.id}-${idx3}`,
          title: level3.deviceName ? `${level3.deviceName}` : `设备ID: ${level3.id}`,
          level: 3,
          rawData: { ...level3 },
          children: [],
        };

        // 第四层：直接处理data数组中的字段（字符串）
        level3.data?.forEach((field: string, idx4: number) => {
          level3Node.children.push({
            key: `L4-${level3.id}-${field}-${idx4}`,
            title: field,  // 直接显示字段名称
            level: 4,
            rawData: { field }, // 存储原始字段数据
            isLeaf: true  // 设置为叶子节点
          });
        });

        treeData.push(level3Node);
      });

  return treeData;
}
